home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93b.txt
/
000089_icon-group-sender _Fri May 14 14:17:41 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-06-16
|
3KB
Received: by cheltenham.cs.arizona.edu; Fri, 14 May 1993 12:27:28 MST
Date: 14 May 1993 14:17:41 -0600 (CST)
From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
Subject: parsing?
To: icon-group@cs.arizona.edu
Message-Id: <01GY60RE36O28WW2YZ@mis.mcw.edu>
Organization: Medical College of Wisconsin (Milwaukee, WI)
X-Vms-To: IN%"icon-group@cs.arizona.edu"
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-Transfer-Encoding: 7BIT
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
> From: IN%"sboisen@bbn.com" 14-MAY-1993 11:03:31.80
> To: IN%"icon-group@cs.arizona.edu"
> Subj: string stripping
> This is so basic it's probably covered in the second week of Icon 101,
> but since i never took the class ...
> If i have a string and i want to strip out certain characters
> (internal ones, so trim won't do it), i can do it like this
> # assume you want to remove hyphens and periods
> full := "abc-def.ghi"
> bare := ""
> badchars := '-.'
> every c := !full do
> # test whether the intersection of c and badchars is empty
> if *(c ** badchars) = 0 then bare ||:= c
HOW ABOUT # procedure parse converts a string into
# a list of strings eliminating delimiters.
full := "abc-def.ghi" # you can then concatenate them, sort them,
bare := "" # or do whatever you like. I put the delim-
badchars := '-.' # iters into a cset which has the effect of
# collapsing them away.
new := parse(full,'-.') #
#
write(image(new)) #
["abc","def","ghi"] #
#
procedure parse(line,delims)
static chars
chars := &cset -- delims
tokens := []
line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
return tokens
end
> But this seems awfully clunky, and i was disappointed that i couldn't
> come up with a tighter way to do it: am i missing some more idiomatic
> way to express this? Note there's two parts that i perceive as clunky:
> the testing of whether c is in badchars (i suppose you could make
> badchars a string and use find instead), and the control structure
> with explicit generation and assignment to a new string.
> Any Icon stylists want to offer some pointers on improvements?
> Sean
Chris Tenaglia (System Manager) | "The past explained,
Medical College of Wisconsin | the future fortold,
8701 W. Watertown Plank Rd. | the present largely appologized for."
Milwaukee, WI 53226 | Organon to The Doctor
(414)257-8765 |
tenaglia@mis.mcw.edu